﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.ComponentModel;

using Willson.JsbManager.Idal;
using Willson.JsbManager.Entity;
using Willson.JsbManager.BllEntity;
using Willson.JsbManager.Comm;

namespace Willson.JsbManager.Bll
{
    /// <summary>
    /// 通用查询业务逻辑类
    /// </summary>
    public class BLLQuery:BaseBLL
    {
        private ITableXtCompany xt_company_DAL = null;

        public BLLQuery()
        {
            xt_company_DAL = Reflect<ITableXtCompany>.Create("DAL_table_xt_company", "Willson.JsbManager.Dal");
        }

        public BEQueryCompanyInfo QueryCompanyInfoByID(int id)
        {
            TableXtCompanyEntity entity = xt_company_DAL.FindByID(id);

            if (entity == null) return null;

            BEQueryCompanyInfo info = new BEQueryCompanyInfo();
            info.Id = entity.Id;
            info.Name = entity.Name;
            info.Address = entity.Address;

            return info;

        }
         
        public BindingList<BEQueryCompanyInfo> QueryCompanyInfo(string text, QueryCompanyType type)
        {
            BindingList<BEQueryCompanyInfo> list = new BindingList<BEQueryCompanyInfo>();

            Hashtable hash = new Hashtable();

            if (type == QueryCompanyType.Pym)
            {
                hash.Add("pym", text);
            }

            if (type == QueryCompanyType.Name)
            {
                hash.Add("name", text);
            }

            IEnumerator<TableXtCompanyEntity> ator = xt_company_DAL.Find(hash, SqlOperator.Like, true).GetEnumerator();

            while (ator.MoveNext())
            {
                BEQueryCompanyInfo info = new BEQueryCompanyInfo();

                info.Id = ator.Current.Id;
                info.Name = ator.Current.Name;
                info.Address = ator.Current.Address;

                list.Add(info);
            }

            return list;
        }
    }
}
